package adminejb;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.validation.ValidationException;

import repositories.FlightRepository;
import specifications.FlightSpecification;
import validator.ValidationService;
import entities.Flight;

@Stateless
@LocalBean
public class FlightBean implements FlightBeanLocal{

    /**
     * Default constructor. 
     */
			
    public FlightBean() {
    }
    
    public void createFlight(Flight flight) {
    	FlightRepository fRep = new FlightRepository();
    	fRep.Add(flight);
    }
    
    public void updateFlight(Flight flight) {
    	FlightRepository fRep = new FlightRepository();
    	fRep.Update(flight);
    }
    
    public void deleteFlight(String id) {
    	FlightRepository fRep = new FlightRepository();
    	fRep.FindAll();
    	FlightSpecification fs = new FlightSpecification("flightNo", id);
    	ArrayList<Flight> list = fRep.findBySpecification(fs);
    	fRep.Delete(list.get(0));
    }
        
    public ArrayList<Flight> getAllFlights() {
    	FlightRepository fr = new FlightRepository();
		fr.FindAll();
		return fr.FlightList;
    }
    
    public Flight findFlight(String attr, String value) {
    	
    	FlightRepository flightRep = new FlightRepository();
    	flightRep.FindAll();
    	FlightSpecification fs = new FlightSpecification(attr, value);
    	ArrayList<Flight> list = flightRep.findBySpecification(fs);
    	return list.get(0);
    	
    }
    

}
